﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIObjects.TreeViewInterfaces;
using AbstraX.ClientInterfaces;
using System.Collections.ObjectModel;
using TreeBuilder.Contracts;
using MvvmTreeView;
using System.Windows.Controls;
using System.Diagnostics;
using SL4PopupMenu;
using System.Windows;

namespace TreeBuilder.ViewModels
{
    public class TreeBuilderTreeNodeRecycleBin : TreeBuilderTreeNodeBase
    {
        private ITreeNodeRecycleBin recycleBin;
        private bool allowDrop;

        public TreeBuilderTreeNodeRecycleBin(ITreeBuilderService treeBuilderService, ITreeView treeView, ITreeNodeRecycleBin recycleBin, ITreeNode parent) : base(treeBuilderService, treeView, parent)
        {
            this.recycleBin = recycleBin;
            this.Tag = recycleBin;
            this.allowDrop = true;
        }

        public override ITreeNodeBase InternalNodeObject
        {
            get
            {
                return recycleBin;
            }
        }

        public override AbstraX.ClientInterfaces.IBase BaseObject
        {
            get
            {
                return recycleBin.BaseObject;
            }

            set
            {
                recycleBin.BaseObject = value;
            }
        }

        public override void Expand()
        {
            if (!this.IsChildrenLoaded)
            {
                recycleBin.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
                recycleBin.LoadChildren();
            }

            base.Expand();
        }

        public override string Text
        {
            get
            {
                return recycleBin.Text;
            }

            set
            {
                recycleBin.Text = value;
            }
        }


        public void Empty(object sender, RoutedEventArgs r)
        {
        }

        public override ContextMenu ContextMenu
        {
            get
            {
                if (contextMenu == null)
                {
                    contextMenu = new ContextMenu
                    {
                        Items = new List<IContextMenuItem>()
                        {
                            new ContextMenuItem
                            {
                                Text = "Empty Recycle Bin",
                                ClickHandler = Empty
                            },
                        }
                    };
                }

                return contextMenu;
            }

            set
            {
                contextMenu = value;
            }
        }

        public override bool? HasChildren
        {
            get { throw new NotImplementedException(); }
        }

        public override string ID
        {
            get 
            {
                return recycleBin.ID;
            }
        }

        public override void LoadChildren()
        {
            recycleBin.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
            recycleBin.LoadChildren();
        }

        public override IEnumerable<ITreeNodeBase> Children
        {
            get 
            {
                return recycleBin.Children;
            }
        }

        public override void Remove()
        {
            MessageBox.Show("The recycle bin cannot be deleted");
        }

        public override bool AllowDrop
        {
            get
            {
                return allowDrop;
            }
            set
            {
                allowDrop = value;
            }
        }

        public override ITreeNode ShallowClone()
        {
            throw new NotImplementedException();
        }

		public override void OnSelect()
		{
		}
        public override ITreeNode DeepClone()
        {
            throw new NotImplementedException();
        }

        public override bool AllowRename
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override bool HasLayoverImage<T>(out T image)
        {
            return recycleBin.HasLayoverImage<T>(out image);
        }

        public override void AddNew(string shortCut)
        {
        }

        public override void DragEnter(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
        {
        }

        public override void DragLeave(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
        {
        }

        public override void DragOver(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
        {
        }

        public override void DragStarting(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
        {
        }

        public override void DragCompleted(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
        {
        }

        public override void ItemDropped(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e, int insertionIndex)
        {
        }

        public override void GiveFeedback(object sender, UIObjects.DragDropInterfaces.GiveFeedbackEventArgs e)
        {
        }

        public override float ChildOrdinal
        {
            get
            {
                return recycleBin.ChildOrdinal;
            }
            set
            {
                recycleBin.ChildOrdinal = value;
            }
        }
    }
}
